/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tree;
class Node {
    String info = "";
    Node leftChild = null;
    Node rightChild = null;
    Node(String rootNode) {
        info = rootNode;
    }
    Node findNode(String inInfo, Node pRoot) {
        Node temp;
        if (pRoot != null) {
            if (pRoot.info == inInfo) {
                return pRoot;
            }
            else {
                temp = pRoot;
                while ((temp != null) && (temp.info != inInfo)) {
                    findNode(inInfo, temp.leftChild);
                    findNode(inInfo, temp.rightChild);
                }
            }
            return temp;
        }
        return null;
    }
    Node modFindNode(String inInfo) {
        if (this != null) {
            if (this.info == inInfo) {
                return this;
            }
            else {
                this.leftChild.modFindNode(inInfo);
                this.rightChild.modFindNode(inInfo);
            }
            return this;
        }
        return null;
    }
    void addNode(Node mam, String newInfo) {
        mam = new Node(newInfo);
    }
}

/**
 *
 * @author Matrix
 */
public class Tree {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Node root = new Node("root");
        System.out.println(root.info);
        root.addNode(root.leftChild,"left");
        root.addNode(root.rightChild,"right");
        System.out.println(root.leftChild.info);
        Node left = root.modFindNode("left");
        //Node left = root.findNode("left", root);
        System.out.println(left.info);

    }

}
